package com.walk.zworld.utils

import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2

object UiUtils {

    /**
     * 修复viewpager+fragment+recyclerview 重新设置viewpager2的滑动灵敏度
     *
     * @param viewPager2
     */
    fun fixViewPager2Rv(viewPager2: ViewPager2?) {
        try {
            val recyclerViewField = ViewPager2::class.java.getDeclaredField("mRecyclerView")
            recyclerViewField.isAccessible = true
            val recyclerView = recyclerViewField[viewPager2] as RecyclerView
            val touchSlopField = RecyclerView::class.java.getDeclaredField("mTouchSlop")
            touchSlopField.isAccessible = true
            val touchSlop = touchSlopField[recyclerView] as Int
            touchSlopField[recyclerView] = touchSlop * 2 //6 is empirical value
        } catch (ignore: Exception) {
        }
    }
}